var proStr;
var proInfo;
var custStr;
var customer;
window.onload = function () {
    var date = new Date();
    //alert("012".slice(-2));
    var month = ("0" + (date.getMonth() + 1)).slice(-2);
    //alert(month);
    date = date.getFullYear()+"-" + month + "-" + date.getDate();
    $("#date").val(date);
    proStr = localStorage.getItem("proInfo");
   // console.log(proStr);
    var totalPrice = 0;
    var str ;
    var product;
    if(proStr != null){
        proInfo = eval("("+ proStr +")");
        for(var  i = 0 ; i < proInfo.length ; i ++ ) {
             product = proInfo[i];
           str += "<div class=\"hairstyle_main\" ><div class=\"hairstyle_main_b\"><div class=\"hairstyle_main_l\"><img src=\"data:image/jpg;base64," + product.productPhoto+"\">"
                +"<div class=\"hairstyle_main_r\"><div class=\"jishi_content2\"><p class=\"t_primary14\" style=\"margin-top:4px;\">" + product.productName + "<span class=\"course_5\" style=\"position: absolute; bottom:15px; left:138px;\">单价： ￥" + product.salePrice + "元<span style=\"font-size: 13px;\"></span></span></p>" +
                "<p style=\"margin-top: 10px;\"><span style=\"margin-right: 20px;\">" +
                "<p><span>数量： " + product.buyAmount + "个</span></p> \n" +
                "</div></div></div></div></div>";
        }
        console.log(str);
        document.getElementById('list').innerHTML = str;
            totalPrice += parseInt(product.buyAmount)*parseInt(product.salePrice);
        ;




          /*  $(".hairstyle_main .hairstyle_main_b .hairstyle_main_l").html("<img src=\"data:image/jpg;base64,"+ product.productPhoto+"\" alt=\"\">");
            //显示商品信息
            $(".jishi_content2").html("<p class=\"t_primary14\" style=\"margin-top:4px;\">"+ product.productName +"<span class=\"course_5\" style=\"position: absolute; bottom:15px; left:138px;\">单价： ￥"+ product.salePrice +"元<span style=\"font-size: 13px;\"></span></span></p> \n" +
                "      \t\t\t\t\t <p style=\"margin-top: 10px;\"><span style=\"margin-right: 20px;\">" +
                "      \t\t\t\t\t <p><span>数量： "+product.buyAmount+ "个</span></p> \n") ;
            /!*  "       \t\t\t\t\t<p style=\"width: 90%; overflow: hidden;text-overflow:ellipsis;white-space:nowrap;\">品牌："+ proInfo.productType +" </p> ");*!/
            totalPrice += parseInt(product.buyAmount)*parseInt(product.salePrice);
        }*/
        $('#totalPrice').val("¥："+totalPrice+"元");
    }
        //alert(proStr);
        //console.log(proInfo);
        //显示图片
    //显示租金
    custStr = localStorage.getItem("customer");
    customer = eval("("+ custStr +")");
    if(customer != null){
        //封装客户信息
        $("#custName").val(customer.custName);
        $("#custPhone").val(customer.custPhone);
        $("#address").val(customer.consigeeAddr);
    }
};

function valiRentDays() {
    /*var date = $("#date").val();
    alert(date);
    console.log(date);*/
}

/*function addRentCart(){
    custStr = localStorage.getItem("customer");
    proStr = localStorage.getItem("proStr");
    var rentTime = $("#date").val();
    //console.log(custStr);
    //console.log(proStr);
    var rentDays = $("#days").val();
    var data = "";
    if(custStr != null){
        data += "customer=" + custStr;

        if(proStr != null){
            data += "&product=" + proStr;
        }else{
            alert("该商品可能已经报废,请返回主页!");
            window.location.href = "/index.html"
        }
    }else{
        alert("用户登陆超时请重新登录!");
        window.location.href = "/login/login.html";
    }
    var url = "rentCart!addRentCart";
    data += "&rentDays=" + rentDays + "&rentTime=" + rentTime;

    sendRequest("post",url,data,addRentCartBack);
}*/

function addRentCartBack(result) {
    alert(result);
    //alert(result == "success");
    if(result == "\"success\""){
        alert("添加成功!");
        window.location.href = "rentCart.html";
    }else{
        alert("租物车加入失败");
    }
}



